// pages/myWallet/myWallet.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imageUrl,
    userInfo: '',
    accountTotal: 0,
    hasBank:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    this.getAccountTotal();
  },
  navito:function(e){//银行卡
    if (this.data.hasBank){
      wx.navigateTo({
        url: '/pages/bankCard/bankCard'
      })
    }else{
      wx.navigateTo({
        url: '/pages/bindingBank/bindingBank'
      })
    }
  },
  withdrawals: function (e) {//提现
    if (this.data.hasBank) {
      wx.navigateTo({
        url: '/pages/withdrawals/withdrawals'
      })
    } else {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '您还没有绑定银行卡，请先绑定银行卡！',
        success: function (res) {
          if (res.confirm) {

          }
        }
      })
    }
  },
  getMyBankCard:function(){
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGyBankCard/getOne', //仅为示例，并非真实的接口地址
      data: {
        userId: this.data.userInfo.id
      },
      success: function (res) {
        if (res.data.success) {
          that.setData({
            hasBank: true
          })
        }else{
          that.setData({
            hasBank: false
          })
        }
      }
    })
  },
  getAccountTotal:function(){
    var that=this;
    wx.request({
      url: app.globalData.httpApiCar + 'userPayInfo/userAccount', //仅为示例，并非真实的接口地址
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        userId: this.data.userInfo.id,
        adds:1
      },
      success: function (res) {
        if (res.data.success) {
          that.setData({
            accountTotal: res.data.data
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMyBankCard();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})